'use strict';
var _ = require('lodash');
exports.index = function*(ctx) {
    const user = yield ctx.service.user.findAll();
    ctx.body = {
        data: user,
        ret_code: "000100",
    };
};
exports.new = function*(ctx) {
    var options = {
        uuid: '560b5202-b927-4da9-8661-32461e5c'+parseInt(Math.random()*10000),
        slug: '45211'+parseInt(Math.random()*10000),
        name: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        password: '$2a$10$KLJY/pN017ie/todF0W6wuNLj9Y/pSsjcQdKTLCMqLuk1AHTDZHSW',
        email: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        created_at: '2017-01-25 14:40:26',
        created_by: '1',
        updated_at: '2017-01-25 14:40:26',
        updated_by: '1'
    }
    const user = yield ctx.service.user.add(options);
    ctx.body = {
        data: user,
        name: 'egg',
        category: 'framework',
        language: 'Node.js',
        api: 'new',
    };
};
exports.create = function*(ctx) {
    ctx.body = {
        name: 'egg',
        category: 'framework',
        language: 'Node.js',
        api: 'create',
    };
};
exports.show = function*(ctx) {
    const user = yield ctx.service.user.find(ctx.params);
    ctx.body = user
};
exports.edit = function*(ctx) {
    var options = {
        id:8,
        uuid: '560b5202-b927-4da9-8661-32461e5c'+parseInt(Math.random()*10000),
        slug: '45211'+parseInt(Math.random()*10000),
        name: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        password: '$2a$10$KLJY/pN017ie/todF0W6wuNLj9Y/pSsjcQdKTLCMqLuk1AHTDZHSW',
        email: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        created_at: '2017-01-25 14:40:26',
        created_by: '1',
        updated_at: '2017-01-25 14:40:26',
        updated_by: '1'
    }
    const user = yield ctx.service.user.edit(options);
    ctx.body = {
        data: user,
        name: 'egg',
        category: 'framework',
        language: 'Node.js',
        api: 'edit',
    };
};
exports.update = function*(ctx) {
    var options = {
        id:8,
        uuid: '560b5202-b927-4da9-8661-32461e5c'+parseInt(Math.random()*10000),
        slug: '45211'+parseInt(Math.random()*10000),
        name: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        password: '$2a$10$KLJY/pN017ie/todF0W6wuNLj9Y/pSsjcQdKTLCMqLuk1AHTDZHSW',
        email: '45211'+parseInt(Math.random()*10000)+'@qq.com',
        created_at: '2017-01-25 14:40:26',
        created_by: '1',
        updated_at: '2017-01-25 14:40:26',
        updated_by: '1'
    }
    const user = yield ctx.service.user.edit(options);
    ctx.body = {
        data: user,
        name: 'egg',
        category: 'framework',
        language: 'Node.js',
        api: 'update',
    };
};
exports.destroy = function*(ctx) {
    //xhr.setRequestHeader('x-csrf-token', csrftoken);
    var options = {
        id:ctx.params.id,
    }
    const user = yield ctx.service.user.delete(options);
    ctx.body = {
        data: user,
        name: 'egg',
        category: 'framework',
        language: 'Node.js',
        api: 'destroy',
    };
};
